package com.relytosoft.mizar.analyze.common.utils;

import cn.hutool.http.HttpUtil;

import java.io.ByteArrayOutputStream;
import java.util.Base64;

/**
 * @author lj
 * @date 2022/5/17 17:11
 */
public class Base64Utils {
    public static String picToBase64(String url) {
        //创建字节数据输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // false:是否关闭输出流
        HttpUtil.download(url, outputStream, true);
        //获取的图片流转为字节数组
        byte[] bytes = outputStream.toByteArray();
        // 用于说明文件格式
        return "data:" + "image/png" + ";base64," +
                Base64.getEncoder().encodeToString(bytes);
    }
}
